package com.hk.service;

import com.hk.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountService {
    @Autowired
    private AccountDao accountDao;
    /**
     *@Transactional  表示这个方法上加了事务
     * readOnly :是否只读，默认是false  如果设置成true，只能用于查询操作
     * Propagation：传播行为
     * Isolation：隔离级别
     * timeout：超时：设置一个时间
     * rollbackFor:设置哪些异常回滚（原本不回滚的编译时异常可以通过此设置回滚）
     * noRollbackFor:设置哪些异常不回滚 默认运行时异常是会回滚的，如果需要不回滚，就设置noRollbackFor
     * @param money :扣多少钱
     * @param nameFrom：从哪个账户扣
     * @param nameTo：加钱到哪个账户
     */
//    @Transactional(noRollbackFor = ArithmeticException.class)
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void TransMoney(int money,String moneyfrom,String moneyto){
        accountDao.DecMoney(money,moneyfrom);
        accountDao.AddMoney(money,moneyto);
    }
    //@Transactional
    public void deal15(){
        accountDao.dealhalf();
        int i = 1/0;
    }
    public void multiMethod(){
        TransMoney(500,"a1","a2");
        deal15();
    }

}
